package com.h3c.ptability.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.util.Result;
import com.h3c.ptability.dto.PtManagementAllDTO;
import com.h3c.ptability.entity.PtManagementAll;
import com.h3c.ptability.service.IPtManagementAllService;
import com.h3c.ptability.support.PageQuery;
import com.h3c.ptability.vo.PtManagementAllVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * PtManagementAll相关api接口
 *
 * @author h24002
 * @date 2023-05-05
 */
@Slf4j
@RestController
@RequestMapping(value = "/manager")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PtManagementAllController {

    private final IPtManagementAllService iPtManagementAllService;

    /**
     * 根据条件查询集合--分页
     *
     * @param pageQuery 查询条件
     * @return 主管信息集合--分页
     */
    @PostMapping("/page")
    public Result<Object> selectPage(@RequestBody PageQuery<PtManagementAllDTO> pageQuery) {
        if (pageQuery.getCondition() == null) {
            pageQuery.setCondition(new PtManagementAllDTO());
        }
        IPage<PtManagementAllVO> pageInfo = iPtManagementAllService.selectPage(pageQuery);
        return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, pageInfo);
    }

    /**
     * 添加数据
     *
     * @param dto 条件
     */
    @PostMapping("/insert")
    public Result<Object> insert(@RequestBody PtManagementAllDTO dto) {
        iPtManagementAllService.insert(dto);
        return new Result(true, StatusCodeEnum.ADD_SUCCESS);
    }

    /**
     * 更新数据
     *
     * @param dto 条件
     */
    @PutMapping("/update")
    public Result<Object> update(@RequestBody PtManagementAllDTO dto) {
        iPtManagementAllService.update(dto);
        return new Result(true, StatusCodeEnum.UPDATE_SUCCESS);
    }

    /**
     * 同步数据
     *
     * @author h24002
     * @date 2023-05-05
     */
    @PostMapping("/syncInfo")
    public Result<Object> syncAllManager() {
        iPtManagementAllService.syncAllManager();
        return new Result(true, StatusCodeEnum.SEARCH_SUCCESS);
    }

    /**
     * 根据条件查询集合
     *
     * @param dto 条件
     * @return 主管信息集合
     */
    @PostMapping("/list")
    public Result<Object> selectList(@RequestBody PtManagementAllDTO dto) {
        List<PtManagementAll> list = iPtManagementAllService.selectList(dto);
        return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, list);
    }
}
